package com.exampleyyy.demoyyy.controller;


//import com.aliyuncs.AcsResponse;
//import com.aliyuncs.DefaultAcsClient;
//import com.aliyuncs.IAcsClient;
//import com.aliyuncs.dysmsapi.model.v20170525.SendSmsRequest;
//import com.aliyuncs.dysmsapi.model.v20170525.SendSmsResponse;
//import com.aliyuncs.exceptions.ClientException;
//import com.aliyuncs.profile.DefaultProfile;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.exampleyyy.demoyyy.JieKouService.UserwxServiceJieKou;
import com.exampleyyy.demoyyy.SHITIYYY.Userwx;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.ObjectUtils;
import org.apache.ibatis.jdbc.Null;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.exampleyyy.demoyyy.common.R;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.Map;
import java.util.Random;

@Slf4j
@RestController
@RequestMapping("/wxapi")
public class wxController {

    @Autowired
    private  UserwxServiceJieKou    fuwuuserwxjiekou;

    @PostMapping("/login")
    public  R<Object> login(@RequestBody Map QianDuanMa,HttpSession session ){

        System.out.println("前端传递来的数据"+QianDuanMa);
        String  QDphone =  QianDuanMa.get("username").toString();
        String  QDpassword = QianDuanMa.get("password").toString();
        String  QDcode = QianDuanMa.get("code").toString();
        System.out.println("前端传递来的数据"+QDpassword+QDphone+QDcode);


        LambdaQueryWrapper<Userwx> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(Userwx::getPhone,QDphone);
        Userwx  userwx =  fuwuuserwxjiekou.getOne(lambdaQueryWrapper);

        if(userwx!=null){// 如果user不等于null,说明数据表没有18311391491
                session.setAttribute("用户信息id",userwx.getId());
                return  R.success(1,"用户已存在",null);
        }else{
                log.info("未登录过,第一次登录,保存数据");
                userwx = new Userwx();
                userwx.setPhone(QDphone);
                userwx.setPassword(QDpassword);
                userwx.setStatus(1);
//                userwx.setName("林黛玉大闹野猪林");
//                userwx.setAvatar("默认头像");
                fuwuuserwxjiekou.save(userwx);
//                session.setAttribute("用户信息id",userwx.getId());
                return  R.success(1,"用户已存储",null);
            }
    }





}